import { services } from '@/config'
import { getCodeObj } from '@/api/space/fyroomland'

const validateCode = (rule, value, callback) => {
  getCodeObj(value).then(response => {
    const result = response.data.data
    console.log(result)
    if (window.boxType === 'edit') {
      if (result && result.length > 0) {
        callback(new Error('土地编号已存在'))
      } else {
        callback()
      }
    }
    if (result && result.length !== 0) {
      callback(new Error('土地编号已存在'))
    } else {
      callback()
    }
  })
}

export const tableOption = {
  column: [
    {
      type: 'input',
      label: '资产名称',
      prop: 'assetName',
      span: 12,
      required: true,
      search: true,
      width: 200,
      rules: [{ required: true, message: '资产名称必须填写' }]
    },
    {
      type: 'input',
      label: '资产编号',
      prop: 'assetNumber',
      span: 12,
      width: 150,
      search: true,
      addDisplay: false,
      editDisabled: true
    },
    {
      type: 'date',
      label: '登记日期',
      prop: 'registrationDate',
      span: 12,
      display: true,
      format: 'yyyy-MM-dd',
      valueFormat: 'yyyy-MM-dd',
      required: true,
      searchRange: true,
      search: true,
      width: 100,
      rules: [{ required: true, message: '登记日期必须填写' }]
    },
    {
      type: 'select',
      label: '使用状况',
      prop: 'status',
      span: 12,
      dicUrl: `${services.adminService}dict/type/room_land_status`,
      cascaderItem: [],
      display: true,
      required: true,
      width: 100,
      rules: [{ required: true, message: '请选择使用状况' }]
    },
    {
      type: 'input',
      label: '土地编号',
      prop: 'landNumber',
      span: 12,
      search: true,
      required: true,
      rules: [
        {
          required: true,
          message: '请输入土地编号',
          trigger: 'blur'
        },
        { validator: validateCode, trigger: 'blur' }
      ]
    },
    { type: 'input', label: '坐落位置', prop: 'location', span: 12, search: true },
    {
      type: 'input',
      label: '使用权类型',
      prop: 'usufructType',
      width: 200,
      span: 12
    },
    { type: 'input', label: '取得方式', prop: 'acquireWay', span: 12 },
    {
      type: 'input',
      label: '批准用途',
      prop: 'permittedUse',
      span: 12
    },
    { type: 'input', label: '实际用途', prop: 'practicalUse', span: 12 },
    {
      type: 'input',
      label: '使用年限',
      prop: 'usefulLife',
      span: 12
    },
    {
      type: 'date',
      label: '取得日期',
      prop: 'builddate',
      format: 'yyyy-MM-dd',
      valueFormat: 'yyyy-MM-dd',
      width: 100,
      span: 12
    },
    { type: 'input', label: '权属性质', prop: 'ownershipType', span: 12 },
    {
      type: 'input',
      label: '权属证明',
      prop: 'ownershipProve',
      span: 12
    },
    { type: 'input', label: '权属证号', prop: 'ownershipNumber', span: 12 },
    {
      type: 'input',
      label: '产权形式',
      prop: 'propertyType',
      span: 12
    },
    {
      type: 'input',
      label: '总面积',
      append: '平米',
      prop: 'overallFloorage',
      span: 12,
      width: 120,
      rules: []
    },
    {
      type: 'input',
      label: '权属面积',
      prop: 'ownershipArea',
      append: '平米',
      span: 12,
      width: 120
    },
    {
      type: 'input',
      label: '基本地价',
      append: '万元',
      prop: 'landPrice',
      span: 12,
      width: 120
    },
    {
      type: 'date',
      label: '发证日期',
      prop: 'issueDate',
      span: 12,
      display: true,
      required: true,
      format: 'yyyy-MM-dd',
      valueFormat: 'yyyy-MM-dd',
      width: 100,
      rules: [{ required: true, message: '发证日期必须填写' }]
    },
    { type: 'input', label: '使用证号', prop: 'landusagePermit', span: 12, search: true },
    {
      type: 'input',
      label: '经度',
      prop: 'x',
      span: 12
    },
    { type: 'input', label: '纬度', prop: 'y', span: 12 },
    {
      type: 'textarea',
      label: '备注',
      prop: 'remarks',
      span: 24,
      display: true
    }
  ],
  labelPosition: 'left',
  labelSuffix: ':',
  labelWidth: 120,
  gutter: 0,
  menuBtn: true,
  submitBtn: true,
  submitText: '提交',
  emptyBtn: true,
  emptyText: '清空',
  menuPosition: 'center',
  border: true,
  index: true,
  indexLabel: '序号',
  stripe: true,
  menuAlign: 'center',
  align: 'center',
  searchMenuSpan: 6,
  viewBtn: true
}
